package com.yyb.controller;

import com.yyb.annotation.AppPermission;
import com.yyb.annotation.Log;
import com.yyb.common.Result;
import com.yyb.domain.SysDictData;
import com.yyb.dto.SysDictDataAddDTO;
import com.yyb.dto.SysDictDataUpdateDTO;
import com.yyb.enums.BusinessType;
import com.yyb.enums.ResultEnums;
import com.yyb.service.SysDictDataService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 
 * 
 * 
 */
@RestController
@RequestMapping("sysDictData")
@Tag(name = "字典数据相关的接口")
public class SysDictDataController extends BaseController {

    @Resource
    private SysDictDataService sysDictDataService;


    /**
     * 添加字典数据
     *   POST http://127.0.0.1:8080/sysDictData/save
     *   接口ID：148742191
     *   接口地址：https://app.apifox.com/link/project/4040316/apis/api-148742191
     */
    @Operation(summary = "添加字典数据")
    @PostMapping("save")
    @AppPermission(value = "system:dictData:add")
    @Log(title = "字典数据管理-添加",businessType = BusinessType.INSERT)
    public Result<?> save(@RequestBody @Validated SysDictDataAddDTO sysDictDataAddDTO){
        int row=this.sysDictDataService.insert(sysDictDataAddDTO);
        return this.toAjax(row>0);
    }

    /**
     * 根据ID查询字典数据
     *   GET http://127.0.0.1:8080/sysDictData/get/{dictCode}
     *   接口ID：148742192
     *   接口地址：https://app.apifox.com/link/project/4040316/apis/api-148742192
     */
    @GetMapping("get/{dictCode}")
    @Operation(summary = "根据ID查询字典数据")
    @AppPermission(value = "system:dictData:query")
    public Result<SysDictData> get(@PathVariable Long dictCode){
        SysDictData sysDictData=this.sysDictDataService.selectByPrimaryKey(dictCode);
        return new Result<>(ResultEnums.SUCCESS,sysDictData);
    }

    /**
     *修改字典数据
     *   PUT http://127.0.0.1:8080/sysDictData/update
     *   接口ID：148742193
     *   接口地址：https://app.apifox.com/link/project/4040316/apis/api-148742193
     */
    @PutMapping("update")
    @Operation(summary = "修改字典数据")
    @AppPermission(value = "system:dictData:update")
    @Log(title = "字典数据管理-修改",businessType = BusinessType.UPDATE)
    public Result<?> update(@RequestBody @Validated SysDictDataUpdateDTO sysDictDataUpdateDTO){
        int row=this.sysDictDataService.updateByPrimaryKey(sysDictDataUpdateDTO);
        return this.toAjax(row>0);
    }

    /**
     * 删除字典数据
     *   DELETE http://127.0.0.1:8080/sysDictData/delete/{dictId}
     *   接口ID：148742194
     *   接口地址：https://app.apifox.com/link/project/4040316/apis/api-148742194
     */
    @DeleteMapping("delete/{dictCode}")
    @Operation(summary = "删除字典数据")
    @AppPermission(value = "system:dictData:remove")
    @Log(title = "字典数据管理-删除",businessType = BusinessType.DELETE)
    public Result<?> delete(@PathVariable Long dictCode){
        int row=this.sysDictDataService.deleteByPrimaryKey(dictCode);
        return this.toAjax(row>0);
    }

    /**
     * 根据字典类型获取字典数据
     *   GET http://127.0.0.1:8080/sysDictData/getDictDataByDictType/{dictType}
     *   接口ID：148742200
     *   接口地址：https://app.apifox.com/link/project/4040316/apis/api-148742200
     */
    @GetMapping("getDictDataByDictType/{dictType}")
    @Operation(summary = "根据字典类型获取字典数据")
    public Result<List<SysDictData>> getDictDataByDictType(@PathVariable String dictType){
        List<SysDictData> sysDictDataList=this.sysDictDataService.getDictDataByDictType(dictType);
        return new Result<>(ResultEnums.SUCCESS,sysDictDataList);
    }
}
